package cn.tedu.supermarket.mapper;

import cn.tedu.supermarket.entity.User;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

@Repository
public interface UserMapper {
    //用户登录注册
    @Insert("insert into buy_user values(null,#{username},#{password},#{mailIndex})")
    Integer addBuyUser(@Param("username") String username, @Param("password") String password, @Param("mailIndex") String mailIndex);

    @Select("select id from buy_user where username=#{username}")
    Integer selectBuyUserByName(String username);

    @Select("select password from buy_user where username=#{username}")
    String selectBuyUserPassword(String username);

    @Select("select id from buy_user where username=#{username} and email=#{email}")
    Integer changeBuyUserPasswordId(@Param("username") String username, @Param("email") String email);

    @Update("update buy_user set password=#{password} where username=#{username}")
    Integer changeBuyUserPassword(@Param("password")String password,@Param("username")String username);

    @Select("select * from buy_user where username=#{username} and password=#{password}")
    User selectBuserByNamePwd(@Param("username") String username, @Param("password") String password);


    //商家登录注册
    @Insert("insert into sel_user values(null,#{username},#{password},#{mailIndex})")
    Integer addSelUser(@Param("username") String username,@Param("password") String password,@Param("mailIndex")String mainIndex);

    @Select("select id from sel_user where username=#{username}")
    Integer selectSelUserByName(String username);

    @Select("select password from sel_user where username=#{username}")
    String selectSelUserPassword(String username);

    @Select("select id from sel_user where username=#{username} and email=#{email}")
    Integer changeSerUserPasswordId(@Param("username") String username, @Param("email") String email);

    @Update("update sel_user set password=#{password} where username=#{username}")
    Integer changeSelUserPassword(@Param("password")String password,@Param("username")String username);

    @Select("select * from sel_user where username=#{username} and password=#{password}")
    User selectSuserByNamePwd(@Param("username") String username, @Param("password") String password);

}
